home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: undoPageDeallocation.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:56:03 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "latch.h"
- #include "semaphore.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "volume.h"
- #include "openlog.h"
- #include "logrecs.h"
- #include "trans.h"
- #include "bitmap.h"
- #include "undo.h"
- #include "io_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "bm_extfuncs.h"
- #include "log_extfuncs.h"
- #include "undo_extfuncs.h"
- #include "logaction.h"
- #include "util_funcs.h"
- #include "thread_globals.h"
-
-
- void
- undoPageDeallocation (
-
- LOGRECORDHDR *recordHeader
- )
- {
-
- register VOLREC *volRec;
- register PID *pidList;
- LIST bitmapList;
- LOGRECORDINFO recordInfo;
- FORCEMARK forceMark;
- LSN lsn;
- LRC *lrcList;
- LRC lrcShortList[LRC_SHORTLIST_SIZE];
- int lrcCount;
- LRC *headerLRC; /* LRC on volume header */
- PAGEALLOCINFO pageAllocInfo;
-
-
- TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
-
- /*
- * get a pointer to the common page allocation info
- * Copy it to a separate area so that it can be updated
- */
- pageAllocInfo = *(PAGEALLOCINFO *) GET_LOG_IMAGE(recordHeader, 0);
- TRPRINT(TR_IO, TR_LEVEL_2, ("numPages:%d", pageAllocInfo.numPages));
-
- /*
- * get a pointer to the name in the record
- */
- pidList = (PID *) GET_LOG_IMAGE(recordHeader, 1);
- TRPRINT(TR_IO, TR_LEVEL_2, ("pid:%d", pidList->page));
-
- if ((volRec = io_FindVolRec(pidList->volid)) == NULL) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
- if (waitSemaphore(&(volRec->headerLink->pageHash->semaphore)) != esmNOERROR) {
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- }
-
- /*
- * intialize the bitmap list
- */
- initializeList( &(bitmapList) );
-
- /*
- * Reallocate the page
- */
- if (io_ReallocPages(pageAllocInfo.page2size,
- (int) pageAllocInfo.numPages, pidList, &bitmapList)) {
-
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * increment the lrc on each bitmap page, and count the
- * number of bitmap pages
- */
- bm_ListIncrementCount(&bitmapList, &lrcCount);
-
- /*
- * Create the lrcList. If its short, use the one on the stack,
- * otherwise malloc space and remember to free it before returning.
- * This is necessary, because the list could potentially be very
- * large, but usually it will be small.
- */
- if (lrcCount <= LRC_SHORTLIST_SIZE) {
- lrcList = lrcShortList;
- } else {
- lrcList = (LRC*) malloc(lrcCount * sizeof(LRC));
- if (lrcList == NULL) {
- SM_ERROR(TYPE_FATAL, esmMALLOCFAILED);
- }
- }
-
- /*
- * Store the lrc for each bitmap page in the lrc list
- */
- bm_ListSaveLrc(&bitmapList, lrcList);
-
- /*
- * Increment the lrc on the volume header
- */
- headerLRC = &(volRec->header->lrc);
- INCREMENT_LRC(headerLRC);
- pageAllocInfo.headerLRC = *headerLRC;
-
- /*
- * initialize the log information
- */
- recordInfo.type = LOG_REC_TYPE_COMPENSATION;
- recordInfo.action = LOG_ACTION_ALLOCATE_PAGE;
- recordInfo.flags = NOFLAGS;
- recordInfo.imageCount = 3;
- recordInfo.actionPid = NULL;
- recordInfo.imageSize[0] = sizeof(PAGEALLOCINFO);
- recordInfo.imageData[0] = (VOID *) &pageAllocInfo;
- recordInfo.imageSize[1] = (unsigned short)
- sizeof(PID) * (pageAllocInfo.numPages);
- recordInfo.imageData[1] = (VOID *) pidList;
- recordInfo.imageSize[2] = sizeof(LRC) * lrcCount;
- recordInfo.imageData[2] = (VOID *) lrcList;
- recordInfo.flags = NOFLAGS;
- recordInfo.nextUndoLSN = recordHeader->previousLSN;
-
- /*
- * write the record to the log
- */
- if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
- &lsn, NOFLAGS)) < 0) {
-
- /*
- * free any malloced list space and return failure
- */
- if (lrcList != lrcShortList) free((char*)lrcList);
- SM_ERROR(TYPE_FATAL, Active->errno);
- }
-
- /*
- * release the bitmap pages and mark them
- */
- bm_ListUnfixDepend( &bitmapList, forceMark, &lsn, lrcList );
-
- /*
- * free any malloced list space
- */
- if (lrcList != lrcShortList) free((char*)lrcList);
-
- /*
- * Mark the volume header dependency
- */
- DEPEND_LOG(volRec->headerLink->pageHash, forceMark, &lsn, headerLRC);
-
- /*
- * release the semaphore on the volume header
- */
- signalSemaphore(&(volRec->headerLink->pageHash->semaphore));
-
- /*
- * Make sure volume is ok
- */
- #ifdef DEBUG
- SM_ASSERT(LEVEL_3, !io_Checker(volRec));
- #endif
- }
-